package com.lwd.controller;

import com.lwd.entity.Admin;
import com.lwd.service.AdminServcie;
import org.springframework.beans.factory.annotation.Autowire;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;

@Controller
public class AdminController {

    @Autowired
    private AdminServcie adminServcie;

    @RequestMapping("doAdminLogin")
    public String doAdminLogin(Admin admin, Model model, HttpSession httpSession){

        Admin queryAdmin = adminServcie.doLogin(admin);
        if(queryAdmin !=null) {
            System.out.println(queryAdmin+"-----------------------------------------");
            httpSession.setAttribute("adminInfo",queryAdmin);
            return "redirect:getAllGoodsMutiFunction";
        }
        else{
            model.addAttribute("message","账号或密码错误请重试");
            return "admin-login";
        }
    }
    @RequestMapping("adminLogout")
    public String adminLogout(HttpSession httpSession){

        httpSession.invalidate();

        return "redirect:/getAllTypeGoods";

    }
}
